﻿#ifndef __DCFRAME_H__
#define __DCFRAME_H__

#include <fcntl.h>

#define ACK_MASK            0x8000

#define DC_COMM_CRC         0

class DCFrame {

public:

    uint8_t     head;       //0xee
    uint8_t*    paload;
    uint16_t    paload_len;

#if DC_COMM_CRC == 1
    uint16_t    crc16;
#endif

    uint8_t     end[4];     //0xff fc ff ff

    //组包 包->数组
    void make_pack(uint8_t* buff, uint16_t* len);

    //解包 数组->包
    void unmake_pack(uint8_t* buff, uint16_t* len);

};

class DCFrameRecv {

public:
    bool proc_one_byte(DCFrame* frame, uint8_t data);

private:

    uint8_t recv_buff[1024] = {0};
    uint16_t recv_len = 0;
    uint16_t recv_index = 0;
};


#endif // CANBUSPORT_H
